﻿<%@ page contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<head>
<title>添加看点</title>
<meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8" />
<link href="<%=request.getContextPath()%>/style/adminStyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.min.js"></script>
<script src="<%=request.getContextPath()%>/js/jquery.min.js"></script>
<script type="text/javascript">
function show1(f) {
    var str = "";
    for (var i = 0; i < f.length; i++) {
        var reader = new FileReader();
        reader.readAsDataURL(f[i]);
        reader.onload = function (e) {
            str += "<img  height='50' width='50' id='img' src='" + e.target.result + "'/>";
            $("#img1")[0].outerHTML = str;
        }
    }        
}
function show2(f) {
    var str = "";
    for (var i = 0; i < f.length; i++) {
        var reader = new FileReader();
        reader.readAsDataURL(f[i]);
        reader.onload = function (e) {
            str += "<img  height='50' width='50' id='img' src='" + e.target.result + "'/>";
            $("#img2")[0].outerHTML = str;
        }
    }        
}
function show3(f) {
	
    var str = "";
    for (var i = 0; i < f.length; i++) {
        var reader = new FileReader();
        reader.readAsDataURL(f[i]);
        reader.onload = function (e) {
        	
        	
            str += "<img  height='50' width='50' id='img' src='" + e.target.result + "'/>";
            $("#img3")[0].outerHTML = str;
        }
    }   
    
   
     
}
</script>
</head>
<body>
 <div class="wrap">
  <div class="page-title">
    <span class="modular fl"><i class="settings"></i><em>看点</em></span>
  </div>
  <form enctype="multipart/form-data">
  <table class="noborder">
   <tr>
    <td style="width:15%;text-align:right;"><b>一级分类：</b></td>
    <td>
     <select class="textBox" id="firstclass">
    <option value="命理">命理</option>
     <option value="风水">风水</option>
     <option value="生肖">生肖</option>
     <option value="星座">星座</option>
     <option value="运势">运势</option>
     </select>
    </td>
   </tr>
   <tr>
    <td style="text-align:right;"><b>二级分类：</b></td>
    <td>
      <input type="text" class="textBox length-long" placeholder="所属媒体..." id="towclass"/>
    </td>
   </tr>
   <tr>
    <td style="text-align:right;"><b>标题：</b></td>
    <td>
      <input type="text" class="textBox length-long" placeholder="看点标题..." id="title"/>
    </td>
   </tr>
   <tr>
  
    <td style="text-align:right;"><b>上传第一块图片：</b></td>
    <td style="width: 50px; height: 50px;"><img height="50" width="50" id="img1" /><input type="file" id="file1" class="inputfile1" onchange="show1(this.files)"  accept="image/*"/> 
	</td>
   </tr>
  
   <tr>
    <td style="text-align:right;"><b>看点第一块内容：</b></td>
    <td><textarea class="textarea"  id="content1"></textarea></td>
   </tr>
   
     <tr>
     
    <td style="text-align:right;"><b>上传第二块图片：</b></td>
    <td style="width: 50px; height: 50px;"><img height="50" width="50" id="img2"  /><input type="file"  id="file2" class="inputfile2" onchange="show2(this.files)"  accept="image/*"/> 
	</td>
   </tr>
 
   
   <tr>
    <td style="text-align:right;"><b>看点第二块内容：</b></td>
    <td><textarea class="textarea"  id="content2"></textarea></td>
   </tr>
   
     <tr>
    
    <td style="text-align:right;"><b>上传第三块图片：</b></td>
     <td style="width: 50px; height: 50px;"><img height="50" width="50" id="img3"  /><input type="file"  id="file3" class="inputfile3" onchange="show3(this.files)"  accept="image/*"/> 
	</td>
    
   </tr>
   <tr>
    <td style="text-align:right;"><b>看点第三块内容：</b></td>
    <td><textarea class="textarea"  id="content3"></textarea></td>
   </tr>
   <tr>
    <td style="text-align:right;"></td>
    <td><input type="button" value="保存" class="tdBtn" onclick="return outlet()"/></td>
   </tr>
  </table>
  </form>
 </div>
 <script type="text/javascript">
 
	
 
 function outlet(){
		var msg = "您确定要添加吗？\n\n请确认！";
		
		var firstclass=$("#firstclass").val();//一级分类
		var towclass=$("#towclass").val();//二级分类
		var title=$("#title").val();
		
		 var file1 = $("#file1")[0].files[0];
		var content1=$("#content1").val();
		
		var file2 = $("#file2")[0].files[0];
		var content2=$("#content2").val();
		
		var file3= $("#file3")[0].files[0];
		var content3=$("#content3").val();
		if(towclass==null||title==null||content1==null||file1==null){
			
			 alert("填写不完整");
			return false;
		}else{
			
		
		var formData = new FormData();
		
		formData.append("title",title);
		formData.append("firstclass",firstclass);
	  	formData.append("towclass",towclass);
		 
	  	
		formData.append("file",file1);
		formData.append("file",file2);
		formData.append("file",file3);
		formData.append("content1",content1);
		
		
		formData.append("content2",content2);

		
		formData.append("content3",content3);
		if (confirm(msg)==true){

			$.ajax({
				"url":"${pageContext.request.contextPath}/Administrators/addtising.do",
				"data":formData,
				"type":"POST",
				"dataType":"json",
				"cache": false,
				"processData": false,
				"contentType": false,
				async: false,
				"success":function(o){
					if(o.state==1){
						 alert("添加成功");
						window.location="${pageContext.request.contextPath}/Administrators/advertising_list.do";
					}else{
						 alert("添加失败");
					}
					
			
				}});
			
		return true;
		}else{
		return false;
		}
		
		}
		}
 
 
 </script>
</body>
</html>